package com.gao.utils;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import org.junit.Test;

public class test1 {
	
	@Test
	public void query() throws SQLException {
		Connection conn = JdbcUtil.getConnection();
		String sql = "select * from TBL_Stu where ID=?";
		PreparedStatement pps = conn.prepareStatement(sql);
		pps.setString(1, "2");
		ResultSet rs = pps.executeQuery();
		if(rs.next()) {
			System.out.println(rs.getString("SZ_NAME"));
		}
		
	}
	public Connection getConnection() {
		try {
			Properties pps = new Properties();
			InputStream in = test1.class.getResourceAsStream("/jdbc.properties");
			pps.load(in);
			String url = pps.getProperty("url");
			String user = pps.getProperty("user");
			String password = pps.getProperty("password");
			String driver = pps.getProperty("driverClass");
			Class.forName(driver);
			return DriverManager.getConnection(url,user,password);
		} catch (Exception e) {
			
			throw new RuntimeException(e);
		} 
	}

}
